Check for FoldersWithPlaceholders when migrating account's folders.
authorCamila Ayres <hello@camilasan.com>
Tue, 14 Jan 2025 16:23:29 +0000 (17:23 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 11 Feb 2025 09:57:01 +0000 (10:57 +0100)
Improve logs.

Signed-off-by: Camila Ayres <hello@camilasan.com>
src/gui/folderman.cpp

index 9b279bbb0d00be2714002364a908670aba741534..6f84af9ad4f108303af1b4eba7f174e3791e400c 100644 (file)
@@ -42,6 +42,7 @@
 namespace {
 constexpr auto settingsAccountsC = "Accounts";
 constexpr auto settingsFoldersC = "Folders";
+constexpr auto settingsFoldersWithPlaceholdersC = "FoldersWithPlaceholders";
 constexpr auto settingsVersionC = "version";
 constexpr auto maxFoldersVersion = 1;
 
@@ -526,89 +527,97 @@ void FolderMan::setupLegacyFolder(const QString &fileNamePath, AccountState *acc
         return;
     }
 
-    settings.beginGroup(settingsAccountsC);
-    qCDebug(lcFolderMan) << "try to migrate accountId:" << accountState->account()->id();
-    settings.beginGroup(accountState->account()->id());
-    settings.beginGroup(settingsFoldersC);
-
-    if (settings.childGroups().isEmpty()) {
-        qCDebug(lcFolderMan) << "there are no legacy folders for accountId:" << accountState->account()->id();
-        return;
-    }
-
-    const auto childGroups = settings.childGroups();
-    for (const auto &alias : childGroups) {
-        settings.beginGroup(alias);
-        qCDebug(lcFolderMan) << "try to migrate folder alias:" << alias;
-
-        const auto path = settings.value(QLatin1String("localPath")).toString();
-        const auto targetPath = settings.value(QLatin1String("targetPath")).toString();
-        const auto journalPath = settings.value(QLatin1String("journalPath")).toString();
-        const auto paused = settings.value(QLatin1String("paused"), false).toBool();
-        const auto ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), false).toBool();
-
-        if (path.isEmpty()) {
-            qCDebug(lcFolderMan) << "localPath is empty";
-            settings.endGroup();
-            continue;
-        }
-
-        if (targetPath.isEmpty()) {
-            qCDebug(lcFolderMan) << "targetPath is empty";
-            settings.endGroup();
-            continue;
+    auto migrateFoldersGroup = [&](const QString &folderGroupName) {
+        const auto childGroups = settings.childGroups();
+        if (childGroups.isEmpty()) {
+            qCDebug(lcFolderMan) << "There are no" << folderGroupName << "to migrate from account" <<  accountState->account()->id();
+            return;
         }
+        for (const auto &alias : childGroups) {
+            settings.beginGroup(alias);
+            qCDebug(lcFolderMan) << "try to migrate" << folderGroupName << "alias:" << alias;
+
+            const auto path = settings.value(QLatin1String("localPath")).toString();
+            const auto targetPath = settings.value(QLatin1String("targetPath")).toString();
+            const auto journalPath = settings.value(QLatin1String("journalPath")).toString();
+            const auto paused = settings.value(QLatin1String("paused"), false).toBool();
+            const auto ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), false).toBool();
+
+            if (path.isEmpty()) {
+                qCDebug(lcFolderMan) << "localPath is empty";
+                settings.endGroup();
+                continue;
+            }
 
-        if (journalPath.isEmpty()) {
-            qCDebug(lcFolderMan) << "journalPath is empty";
-            settings.endGroup();
-            continue;
-        }
+            if (targetPath.isEmpty()) {
+                qCDebug(lcFolderMan) << "targetPath is empty";
+                settings.endGroup();
+                continue;
+            }
 
-        FolderDefinition folderDefinition;
-        folderDefinition.alias = alias;
-        folderDefinition.localPath = path;
-        folderDefinition.targetPath = targetPath;
-        folderDefinition.journalPath = journalPath;
-        folderDefinition.paused = paused;
-        folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles;
-
-        if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
-            auto ok = true;
-            auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
-                                                                                   &ok);
-            if (!ok) {
-                qCInfo(lcFolderMan) << "There was a problem retrieving the database selective sync for " << folder;
+            if (journalPath.isEmpty()) {
+                qCDebug(lcFolderMan) << "journalPath is empty";
+                settings.endGroup();
+                continue;
             }
 
-            legacyBlacklist << settings.value(QLatin1String("blackList")).toStringList();
-            if (!legacyBlacklist.isEmpty()) {
-                qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
-                for (const auto &legacyFolder : legacyBlacklist) {
-                    folder->migrateBlackListPath(legacyFolder);
+            qCDebug(lcFolderMan) << folderGroupName << "located at" << path;
+
+            FolderDefinition folderDefinition;
+            folderDefinition.alias = alias;
+            folderDefinition.localPath = path;
+            folderDefinition.targetPath = targetPath;
+            folderDefinition.journalPath = journalPath;
+            folderDefinition.paused = paused;
+            folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles;
+
+            if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
+                auto ok = true;
+                auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
+                                                                                 &ok);
+                if (!ok) {
+                    qCInfo(lcFolderMan) << "There was a problem retrieving the database selective sync for " << folder;
+                }
+
+                legacyBlacklist << settings.value(QLatin1String("blackList")).toStringList();
+                if (!legacyBlacklist.isEmpty()) {
+                    qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
+                    for (const auto &legacyFolder : legacyBlacklist) {
+                        folder->migrateBlackListPath(legacyFolder);
+                    }
+                    settings.remove(QLatin1String("blackList"));
                 }
-                settings.remove(QLatin1String("blackList"));
-            }
 
-            folder->saveToSettings();
+                folder->saveToSettings();
 
-            qCInfo(lcFolderMan) << "Migrated!" << folder->path();
-            settings.sync();
+                qCInfo(lcFolderMan) << "Migrated!" << folder->path();
+                settings.sync();
 
-            if (!folder) {
-                continue;
-            }
+                if (!folder) {
+                    continue;
+                }
 
-            scheduleFolder(folder);
-            emit folderSyncStateChange(folder);
+                scheduleFolder(folder);
+                emit folderSyncStateChange(folder);
+            }
+            settings.endGroup(); // folder alias
         }
+    };
 
-        settings.endGroup();
-    }
+    settings.beginGroup(settingsAccountsC);
+    qCDebug(lcFolderMan) << "try to migrate accountId:" << accountState->account()->id();
+    settings.beginGroup(accountState->account()->id());
 
+    settings.beginGroup(settingsFoldersWithPlaceholdersC);
+    migrateFoldersGroup(settingsFoldersWithPlaceholdersC);
     settings.endGroup();
+
+    settings.beginGroup(settingsFoldersC);
+    migrateFoldersGroup(settingsFoldersC);
     settings.endGroup();
 
+    settings.endGroup();
+    settings.endGroup();
     return;
 }